package 快乐数;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 快乐数
 * @date 2022/10/16 10:46
 */
public class Demo209 {
    Set res=new HashSet();
    public boolean isHappy(int n) {

           Integer sum=0;
           while (n>0){
              int s=n%10;
              sum=sum+s*s;
              n=n/10;
          }
          if(sum==1){
              return true;
          }
          if(res.contains(sum)){
              return false;
          }
          res.add(sum);
          return isHappy(sum);
    }
}
